package gui;

import gestionBDD.requetesAlbum;
import gestionBDD.requetesContient;
import gestionBDD.requetesImage;
import interne.Contient;
import interne.Image;

import com.trolltech.qt.gui.*;

import java.sql.*;

public class fenetrePhotoEdition extends QWidget {
	
	Contient contient ;
	Image image ;
	
	private QLineEdit titreimageLineEdit ;
    private QLineEdit commentaireLineEdit ;
    private QLineEdit ordreLineEdit ;
    
    private QLineEdit appareilphotoLineEdit ;
    private QLineEdit objectifLineEdit ;
    private QLineEdit distfocaleLineEdit ;
    private QLineEdit sensibiliteisoLineEdit ;
    private QLineEdit ouvertureLineEdit ;
    private QLineEdit vitesseobturationLineEdit ;
    private QLineEdit resolutionLineEdit ;
	
	public fenetrePhotoEdition(Contient c) throws SQLException {
		
		setContient(c) ;
		setImage(new Image(contient.getIdImage()));
		setImage(requetesImage.trouverAvecId(image));
		
		/** Chemin's GroupBox' **/
        QGroupBox cheminGroup = new QGroupBox(tr("Photo"));
        
        /* Chemin Line Edit with Label */
        QLabel albumLabel = new QLabel(tr("Album :"));
        QLabel albumLineEdit = new QLabel(tr(requetesAlbum.retourneTitreAlbum(contient.getIdAlbum())));

        /* Chemin Line Edit with Label */
        QLabel titreLabel = new QLabel(tr("Titre :"));
        titreimageLineEdit = new QLineEdit(contient.getTitreImage());

        /* Ordre Line Edit with Label */
        QLabel ordreLabel = new QLabel(tr("Ordre :"));
        ordreLineEdit = new QLineEdit(contient.getOrdre().toString());
        
        /* Chemin Line Edit with Label */
        QLabel commentaireLabel = new QLabel(tr("Commentaire :"));
        commentaireLineEdit = new QLineEdit(contient.getCommentaire());
        
        /* Chemin's Layout */
        QGridLayout cheminLayout = new QGridLayout();
        cheminLayout.addWidget(albumLabel, 0, 0);
        cheminLayout.addWidget(albumLineEdit, 0, 1);
        cheminLayout.addWidget(ordreLabel, 1, 0);
        cheminLayout.addWidget(ordreLineEdit, 1, 1);
        cheminLayout.addWidget(titreLabel, 2, 0) ;
        cheminLayout.addWidget(titreimageLineEdit, 2, 1) ;
        cheminLayout.addWidget(commentaireLabel, 3, 0) ;
        cheminLayout.addWidget(commentaireLineEdit, 3, 1) ;
        
        cheminGroup.setLayout(cheminLayout);
        
        /** Détails' GroupBox' **/
        QGroupBox detailsGroup = new QGroupBox(tr("Détails"));	
        
        /* Chemin Line Edit with Label */
        QLabel cheminLabel = new QLabel(tr("Chemin :"));
        QLabel cheminLineEdit = new QLabel(tr(image.getChemin()));
        QLabel appareilphotoLabel = new QLabel(tr("Appareil Photo :"));
        appareilphotoLineEdit = new QLineEdit(image.getAppareilPhoto());
        /* Chemin Line Edit with Label */
        QLabel objectifLabel = new QLabel(tr("Objectif :"));
        objectifLineEdit = new QLineEdit(image.getObjectif());
        /* Chemin Line Edit with Label */
        QLabel distfocaleLabel = new QLabel(tr("Distance focale :"));
        distfocaleLineEdit = new QLineEdit(image.getDistFocale().toString());
        /* Chemin Line Edit with Label */
        QLabel sensibiliteisoLabel = new QLabel(tr("Sensibilite ISO :"));
        sensibiliteisoLineEdit = new QLineEdit(image.getSensibiliteISO().toString());
        /* Chemin Line Edit with Label */
        QLabel ouvertureLabel = new QLabel(tr("Ouverture :"));
        ouvertureLineEdit = new QLineEdit(image.getOuverture());
        /* Chemin Line Edit with Label */
        QLabel vitesseobturationLabel = new QLabel(tr("Vitesse obturation :"));
        vitesseobturationLineEdit = new QLineEdit(image.getVitesseObturation().toString());
        /* Chemin Line Edit with Label */
        QLabel resolutionLabel = new QLabel(tr("Résolution :"));
        resolutionLineEdit = new QLineEdit(image.getResolution());
        
        /* Login's Layout */
        QGridLayout detailsLayout = new QGridLayout();
        detailsLayout.addWidget(cheminLabel, 0, 0);
        detailsLayout.addWidget(cheminLineEdit, 0, 1);
        detailsLayout.addWidget(appareilphotoLabel, 1, 0);
        detailsLayout.addWidget(appareilphotoLineEdit, 1, 1);
        detailsLayout.addWidget(resolutionLabel, 2, 0);
        detailsLayout.addWidget(resolutionLineEdit, 2, 1);   
        detailsLayout.addWidget(objectifLabel, 3, 0);
        detailsLayout.addWidget(objectifLineEdit, 3, 1);
        detailsLayout.addWidget(distfocaleLabel, 4, 0);
        detailsLayout.addWidget(distfocaleLineEdit, 4, 1);
        detailsLayout.addWidget(sensibiliteisoLabel, 5, 0);
        detailsLayout.addWidget(sensibiliteisoLineEdit, 5, 1);
        detailsLayout.addWidget(ouvertureLabel, 6, 0);
        detailsLayout.addWidget(ouvertureLineEdit, 6, 1);
        detailsLayout.addWidget(vitesseobturationLabel, 7, 0);
        detailsLayout.addWidget(vitesseobturationLineEdit, 7, 1);
        detailsGroup.setLayout(detailsLayout);
        
        /* Ok Button Box */
        QDialogButtonBox boutonOk = new QDialogButtonBox();
        boutonOk.addButton(QDialogButtonBox.StandardButton.Ok);
        boutonOk.clicked.connect(this, "modifierPhoto()");
        
        // Dialog Layout
        QGridLayout layout = new QGridLayout();
        layout.addWidget(cheminGroup, 0, 0);
        layout.addWidget(detailsGroup, 1, 0);
        layout.addWidget(boutonOk, 2, 1);
        setWindowTitle(tr("Editer Photo"));
        setLayout(layout);
	}
	
	public void modifierPhoto() throws SQLException {
		contient.setOrdre(Integer.parseInt(ordreLineEdit.text()));
		contient.setTitreImage(titreimageLineEdit.text());
		contient.setCommentaire(commentaireLineEdit.text());
		requetesContient.modifierContient(contient) ;
		Image i = new Image(contient.getIdImage(), image.getChemin(), 
				appareilphotoLineEdit.text(),
				resolutionLineEdit.text(),
				objectifLineEdit.text(), 
				distfocaleLineEdit.text(), 
				sensibiliteisoLineEdit.text(), 
				ouvertureLineEdit.text(), 
				vitesseobturationLineEdit.text()); 
		requetesImage.modifierImage(i) ;
		this.hide();
	}

	public Contient getContient() {
		return contient;
	}

	public void setContient(Contient contient) {
		this.contient = contient;
	}

	public Image getImage() {
		return image;
	}

	public void setImage(Image image) {
		this.image = image;
	}
	
	
}
